import Vue from 'vue'
import Router from 'vue-router'

import Main from '../components/Main.vue'
import Menus from '../components/ademin/Menus.vue'
import Roles from '../components/ademin/Roles.vue'
//es6实现懒加载

import Rep from '@/router/inventory/repseting'
import pro from '@/router/promanger'
import purchaseademin from '@/router/purchase'
import productDesign from '@/router/productDesign/productDesignSeting'
const Users = () => import("../components/ademin/Users.vue")
const Login = () => import("../components/Login/Login.vue")
Vue.use(Router)

const router = new Router({
  routes: [{
      path: '/',
      name: 'Login',
      component: Login
    }, {
      path: '/login',

      redirect: "/"
    },
    {
      path: '/main',
      name: 'mian',
      component: Main,
      children: [{
          name: 'menus',
          path: 'menus',
          component: Menus
        }, {
          name: 'roles',
          path: 'roles',
          component: Roles
        }, {
          name: 'users',
          path: 'users',
          component: Users
        },
        ...Rep,
        ...pro,
        ...productDesign,
        ...purchaseademin
      ]
    }
  ]
})

// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
// router.beforeEach((to, from, next) => {
//   if (to.path == '/login' ||to.path == '/') {
//     next();
//   } else {
//     let token = localStorage.getItem('token');
//     if (token === 'null' || token === '') {
//       next('/login');
//     } else {
//       next();
//     }
//   }
// });
// returnFun(){   // 退出登录
// 	 MessageBox.confirm(this.lang.logoutTip).then(action => {
// 	     this.$store.commit('$_removeStorage');    // 清除登录信息
// 	     this.$router.push({
// 	         name:'login'
// 	     });
// 	     Toast({message:this.lang.logoutSuccess, duration: 1500});
// 	 }).catch(()=>{})
// }

export default router;
